import React, { Component } from 'react'

export default class TestUpdate extends Component {
    state = {
        count:1
    }
    /**
     * 执行时机：组件更新完成之后触发
     * 作用：
     * 1. 数据进行本地缓存时使用
     * 
     */
    componentDidUpdate(){
        console.log('componentDidUpdate')
    }
    render() {
        console.log('render')
        let {count} = this.state;
        let {msg} = this.props
        return (
            <div>
                <h4>TestUpdate</h4>
                <p>state count: {count}</p>
                <p>props msg: {msg}</p>
                <p><button onClick={()=>this.setState({count:count + 1})}>count++</button></p>
                <p><button onClick={()=>this.setState({count:2})}>更新到2</button></p>
                <p><button onClick={()=>this.forceUpdate()}>强制更新</button></p>
            </div>
        )
    }
}
